package com.atguigu.lease.common.aliyunOss;

import com.aliyun.oss.ClientBuilderConfiguration;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class AliyunOssConfiguration {

    @Autowired
    private OssProperties ossProperties;

    /**
     * 创建OSS客户端Bean
     * @return OSS客户端实例
     */
    @Bean
    public OSS ossClient() {
        log.info("正在创建OSS客户端，endpoint: {}, accessKeyId: {}, bucketName: {}", 
                ossProperties.getEndpoint(), 
                ossProperties.getAccessKeyId(), 
                ossProperties.getBucketName());
        
        return new OSSClientBuilder()
                .build(ossProperties.getEndpoint(), 
                       ossProperties.getAccessKeyId(), 
                       ossProperties.getAccessKeySecret(), 
                       new ClientBuilderConfiguration());
    }
}